package matlap.server;

//FONTOS: a scores tablaban a score tipusat at kell allitani int-re!!
import java.sql.Connection;
import java.util.List;

import matlap.client.services.student.StudentService;
import matlap.database.ConnectionManager;
import matlap.database.dao.DAOFactory;
import matlap.database.dao.StudentDAO;

import matlap.shared.Score;
import matlap.shared.Student;
import matlap.shared.exceptions.MyException;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * The server side implementation of the RPC service.
 */

public class StudentServiceImpl extends RemoteServiceServlet implements
		StudentService {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	DAOFactory df = DAOFactory.getInstance();
	StudentDAO sd = df.getStudentDAO();
	Connection con = null;
	ConnectionManager conman = null;

	/**
	 * Turns back the students number from the people table.
	 */

	public int getStudentsNumber() {
		return sd.getStudentsNumber();
	}

	/**
	 * Turns back the students from the people table in Student list.
	 */

	public List<Student> getStudents() {
		return sd.getStudents();
	}

	/**
	 * Turns back the students name from the people table in a String list.
	 */
	public List<String> getStudentsName() {
		return sd.getStudentsName();
	}

	/**
	 * Turns back the schools from the school table in a Student list.
	 */

	public List<Student> selectSchools() {
		return sd.selectSchools();
	}

	/**
	 * Turns back the students name from the people table in a String list.
	 */

	public List<Student> selectStudentsName() {
		return sd.selectStudentsName();
	}

	public List<Student> selectGrades() {
		return sd.selectGrades();
	}

	/**
	 * Turns back the localities name from the locality table in a Student list.
	 */

	public List<Student> selectLocalities() {
		return sd.selectLocalities();
	}

	public List<String> getUserNames() {
		return sd.getUserNames();
	}

	/**
	 * Deletes a student from scores, students, registered and people tables by
	 * adding userName.
	 * @throws MyException 
	 */
	public void deleteStudent(String userName) throws MyException {
		sd.deleteStudent(userName);
	}

	/**
	 * Updates a student in the people table by adding userName, last name.
	 * first name, address, school name and class.
	 * @throws MyException 
	 */
	public void updatePeopleStudents(String userName, String lastName,
			String firstName, String address, String schoolName, int classNr) throws MyException {
		sd.updatePeopleStudents(userName, lastName, firstName, address,
				schoolName, classNr);
	}

	public Student getStudentByUserName(String userName) {
		return sd.getStudentByUserName(userName);
	}

	public void updateStudents(String userName, int schoolID, int classNr) throws MyException {
		sd.updateStudents(userName, schoolID, classNr);
	}

	/**
	 * Updates a student in the people table by adding userName, last name.
	 * first name, address, school name and class.
	 */
	/**
	 * Turns back the schoolID from the school table by adding schools name.
	 */
	public int selectSchoolID(String schoolName) {
		return sd.selectSchoolID(schoolName);
	}

	/**
	 * Updates a student in the student table by adding username, schoolID and
	 * class.
	 */

	/**
	 * Turns back the schoolID from the school table by adding schools name.
	 */

	/**
	 * Updates a student in the people registered and students tables by adding
	 * Student.
	 * @throws MyException 
	 */
	public void update(Student student) throws MyException {
		sd.update(student);
	}

	/**
	 * Updates a student in the people registered and students tables by adding
	 * Student.
	 */
	/**
	 * Turns back students score from the scores tables.
	 */

	public List<Score> selectStudentsScore() {
		return sd.selectStudentsScore();
	}

	/**
	 * Inserts a student score into the scores tables by adding Score.
	 */

	public void insertStudentScore(Score s) {
		sd.insertStudentScore(s);
	}

	/**
	 * Updates the students score in the scores table by adding Acore.
	 */

	@Override
	public List<Student> selectStudentsWithoutScore() {
		return sd.selectStudentsWithoutScore();
	}

	public void updateStudentScore(Score s) throws MyException {
		sd.updateStudentScore(s);
	}

	@Override
	public List<Student> getStudentsBy(String name, String string,
			String string2, String string3) {
		// TODO Auto-generated method stub
		return sd.getStudentsBy(name, string, string2, string3);
	}

	/**
	 * Turns back the students from the people, students, school and locality
	 * tables in a Student list by adding student name, school, grade and
	 * locality.
	 */

	@Override
	public Student getStudentByUserName2(String userName) {
		return sd.getStudentByUserName2(userName);
	}

	@Override
	public Student getStudentPeopleByUserName(String username) {
		return sd.getStudentByUserName(username);
	}

}